package com.example.petadopt.service;

import com.example.petadopt.dao.AdoptApplyDao;
import com.example.petadopt.dao.PetDao;
import com.example.petadopt.entity.AdoptionApplication;
import com.example.petadopt.entity.Pet;
import com.example.petadopt.entity.AdoptApply;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PetService {
    @Autowired
    private PetDao petDao;
    @Autowired
    private AdoptApplyDao adoptApplyDao;

    // 根据用户 ID 获取用户发布的所有宠物及其领养申请信息
    public List<Pet> getPetWithAdoptApplyByUserId(int userId) {
        // 获取用户发布的所有宠物
        List<Pet> pets = petDao.findByPetUserId(userId);

        // 为每个宠物查询相关的领养申请信息
        for (Pet pet : pets) {
            List<AdoptionApplication> adoptApplies = adoptApplyDao.getAdoptApplyByAdoptPetId(pet.getPetId());
            pet.setAdoptApplies(adoptApplies); // 假设 Pet 实体类中有一个字段来存储领养申请信息
        }
        return pets;
    }
}